<?php
// +----------------------------------------------------------------------
// | 萤火商城系统 [ 致力于通过产品和服务，帮助商家高效化开拓市场 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2024 https://www.yiovo.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 这不是一个自由软件，不允许对程序代码以任何形式任何目的的再发行
// +----------------------------------------------------------------------
// | Author: 萤火科技 <admin@yiovo.com>
// +----------------------------------------------------------------------
declare (strict_types = 1);

namespace app\common\model\learn;

use cores\BaseModel;
use think\model\relation\HasOne;

/**
 * 聊天记录
 * Class Category
 * @package app\common\model
 */
class ChatLog extends BaseModel {
	// 定义表名
	protected $name = 'learn_chat_log';
	// 定义主键
	protected $pk = 'log_id';


// 追加字段
	protected $append = ['time'];
	public function getTimeAttr($value, $data) {
		$time = strtotime(Date('Y-m-d'));
		if ($data['create_time']>=$time) {
			$time = Date('H:i',$data['create_time']);
		}else{
			$time = Date('m月d日 H:i',$data['create_time']);
		}
		
		return $time;
	}
	
	/**
	 * 关联用户表
	 * @return BelongsTo
	 */
	public function user() {
		$model = "app\\common\\model\\User";
		return $this->belongsTo($model,'follow_id','user_id')->field(['user_id', 'nick_name', 'avatar_id']);
	}
}
